﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
<script type="text/javascript">

    var gridWin = "#grid-table";
    var pagerWin = "#grid-pager";
    var gridBusi = "#grid-Busi-table";
    var gridUser = "#grid-User-table";

    $(function () {
        $('body').layout({
            west__size: 0.5,
            center__childOptions: {
                north__size: 0.5,
                north__closable: false
            }
        });
        initBusiData();
        initUserData();
        $(gridWin).jqGrid({
            url: "/TWindow/GetGridData",
            datatype: "json",
            height: $(document).height() - 128,
            colModel: [
                { label: 'ID', name: 'ID', width: 60, sorttype: "int", key: true },
                { label: '窗口名称', name: 'Name' },
                { label: '窗口号', name: 'Number' },
                { label: '窗口状态', name: 'State' },
                { label: '呼叫器编号', name: 'CallNumber' },
                { label: '区域名称', name: 'AreaName' }
        ],
            rowNum: 10,
            rowList: [10, 30, 50],
            loadonce: true,
            pager: pagerWin,
            autowidth: true,
            loadComplete: function () {
                var table = this;
                setTimeout(function () {
                    updatePagerIcons(table);
                }, 0);
                $(gridWin).selectFirstRow();
            },
            onSelectRow: function (id) {
                refreshDetailData(id);
            }
        });
    });

    function refreshDetailData(id) {
        $.ajax({
            url: "/TWindow/GetGridDetailData?winId=" + id,
            dataType: "json",
            success: function (data) {
                refreshBusiData(data.busiData);
                refreshUserData(data.userData);
            }
        });
    }

    function initBusiData() {
        $(gridBusi).jqGrid({
            datatype: 'local',
            data: [],
            height: $(document).height() / 2 - 88,
            colModel: [
                { label: 'ID', name: 'ID', key: true, hidden: true },
                { label: '所属部门ID', width: 80, name: 'unitSeq' },
                { label: '所属部门名称', name: 'unitName' },
                { label: '业务流水号', width: 80, name: 'busiSeq' },
                { label: '业务名称', name: 'busiName' }
        ],
            autowidth: true,
            loadComplete: function () {
                var table = this;
                setTimeout(function () {
                    updatePagerIcons(table);
                }, 0);
                $(gridBusi).selectFirstRow();
            }
        });
    }

    function initUserData() {
        $(gridUser).jqGrid({
            datatype: 'local',
            data: [],
            height: $(document).height() / 2 - 88,
            colModel: [
                { label: 'ID', name: 'ID', key: true, hidden: true },
                { label: '用户ID', name: 'UserID', width: 60 },
                { label: '用户名', name: 'UserName' }
        ],
            autowidth: true,
            loadComplete: function () {
                var table = this;
                setTimeout(function () {
                    updatePagerIcons(table);
                }, 0);
                $(gridUser).selectFirstRow();
            }
        });
    }

    function refreshBusiData(griddata) {
        $(gridBusi).jqGrid('clearGridData');
        $(gridBusi).jqGrid('setGridParam', {
            datatype: 'local',
            data: griddata
        }).trigger("reloadGrid");
    }

    function refreshUserData(griddata) {
        $(gridUser).jqGrid('clearGridData');
        $(gridUser).jqGrid('setGridParam', {
            datatype: 'local',
            data: griddata
        }).trigger("reloadGrid");
    }

    function Add() {
        $.modalOpen({
            title: "窗口管理 - 新增",
            url: "SystemConfig/TWindow/Form?id=-1",
            callback: function () {
                $.modalContent().submitForm(function () {
                    Refresh();
                });
            }
        });
    }

    function Edit() {
        var sid = $(gridWin).jqGrid('getGridParam', 'selrow');
        if (sid == null) {
            alert("没有任何选中行！");
            return;
        }
        $.modalOpen({
            title: "窗口管理 - 编辑",
            url: "SystemConfig/TWindow/Form?id=" + sid,
            callback: function () {
                $.modalContent().submitForm(function () {
                    Refresh();
                });
            }
        });
    }

    function Delete() {
        var sid = $(gridWin).jqGrid('getGridParam', 'selrow');
        if (sid == null) {
            alert("没有任何选中行！");
            return;
        }
        $.modalConfirm({
            text: "确定删除该记录吗？",
            callback: function () {
                $.deleteForm({
                    url: "TWindow/DeleteForm?id=" + sid,
                    callback: function () {
                        Refresh();
                    }
                });
            }
        });
    }

    function View() {
        var sid = $(gridWin).jqGrid('getGridParam', 'selrow');
        if (sid == null) {
            alert("没有任何选中行！");
            return;
        }
        $.modalOpen({
            title: "窗口管理 - 查看",
            url: "SystemConfig/TWindow/Form?id=" + sid,
            view: true
        });
    }

    function Refresh() {
        $(gridWin).setGridParam({ datatype: 'json', page: 1 }).trigger('reloadGrid');
    }

    function RefreshDetail() {
        var id = $(gridWin).jqGrid('getGridParam', 'selrow');
        $(gridWin).setSelection(id);
    }

    //对应业务
    function BusiAdd() {
        var winId = $(gridWin).jqGrid('getGridParam', 'selrow');
        if (winId == null) {
            alert("没有选中窗口！");
            return;
        }
        $.modalOpen({
            title: "窗口业务对应 - 新增",
            url: "SystemConfig/TWindow/BusiForm?id=-1&winId=" + winId,
            callback: function () {
                $.modalContent().submitForm(function () {
                    RefreshDetail();
                });
            }
        });
    }

    function BusiEdit() {
        var sid = $(gridBusi).jqGrid('getGridParam', 'selrow');
        if (sid == null) {
            alert("没有任何选中行！");
            return;
        }
        $.modalOpen({
            title: "窗口业务对应 - 编辑",
            url: "SystemConfig/TWindow/BusiForm?id=" + sid,
            callback: function () {
                $.modalContent().submitForm(function () {
                    RefreshDetail();
                });
            }
        });
    }

    function BusiDelete() {
        var sid = $(gridBusi).jqGrid('getGridParam', 'selrow');
        if (sid == null) {
            alert("没有任何选中行！");
            return;
        }
        $.modalConfirm({
            text: "确定删除该记录吗？",
            callback: function () {
                $.deleteForm({
                    url: "TWindow/DeleteBusiForm?id=" + sid,
                    callback: function () {
                        RefreshDetail();
                    }
                });
            }
        });
    }

    function BusiView() {
        var sid = $(gridBusi).jqGrid('getGridParam', 'selrow');
        if (sid == null) {
            alert("没有任何选中行！");
            return;
        }
        $.modalOpen({
            title: "窗口业务对应 - 查看",
            url: "SystemConfig/TWindow/BusiForm?id=" + sid,
            view: true
        });
    }


    //对应用户
    function UserAdd() {
        var winId = $(gridWin).jqGrid('getGridParam', 'selrow');
        if (winId == null) {
            alert("没有选中窗口！");
            return;
        }
        $.modalOpen({
            title: "窗口用户对应 - 新增",
            url: "SystemConfig/TWindow/UserForm?id=-1&winId=" + winId,
            callback: function () {
                $.modalContent().submitForm(function () {
                    RefreshDetail();
                });
            }
        });
    }

    function UserEdit() {
        var sid = $(gridUser).jqGrid('getGridParam', 'selrow');
        if (sid == null) {
            alert("没有任何选中行！");
            return;
        }
        $.modalOpen({
            title: "窗口用户对应 - 编辑",
            url: "SystemConfig/TWindow/UserForm?id=" + sid,
            callback: function () {
                $.modalContent().submitForm(function () {
                    RefreshDetail();
                });
            }
        });
    }

    function UserDelete() {
        var sid = $(gridUser).jqGrid('getGridParam', 'selrow');
        if (sid == null) {
            alert("没有任何选中行！");
            return;
        }
        $.modalConfirm({
            text: "确定删除该记录吗？",
            callback: function () {
                $.deleteForm({
                    url: "TWindow/DeleteUserForm?id=" + sid,
                    callback: function () {
                        RefreshDetail();
                    }
                });
            }
        });
    }

    function UserView() {
        var sid = $(gridUser).jqGrid('getGridParam', 'selrow');
        if (sid == null) {
            alert("没有任何选中行！");
            return;
        }
        $.modalOpen({
            title: "窗口用户对应 - 查看",
            url: "SystemConfig/TWindow/UserForm?id=" + sid,
            view: true
        });
    }

</script>
<div class="ui-layout-west">
    <div class="btn-group">
        <button class="btn btn-sm btn-primary" onclick="Add()">
            <i class="icon-plus-sign bigger-110"></i>新增</button>
        <button class="btn btn-sm btn-success" onclick="Edit()">
            <i class="icon-pencil bigger-110"></i>编辑</button>
        <button class="btn btn-sm btn-danger" onclick="Delete()">
            <i class="icon-minus-sign bigger-110"></i>删除</button>
        <button class="btn btn-sm btn-yellow" onclick="View()">
            <i class="icon-zoom-in bigger-110"></i>查看</button>
        <button class="btn btn-sm btn-info" onclick="Refresh()">
            <i class="icon-refresh bigger-110"></i>刷新</button>
    </div>
    <table id="grid-table">
    </table>
    <div id="grid-pager">
    </div>
</div>
<div class="ui-layout-center">
    <div class="ui-layout-north">
        <div class="btn-group">
            <button class="btn btn-sm btn-primary" onclick="BusiAdd()">
                <i class="icon-plus-sign bigger-110"></i>新增</button>
            <button class="btn btn-sm btn-success" onclick="BusiEdit()">
                <i class="icon-pencil bigger-110"></i>编辑</button>
            <button class="btn btn-sm btn-danger" onclick="BusiDelete()">
                <i class="icon-minus-sign bigger-110"></i>删除</button>
            <button class="btn btn-sm btn-yellow" onclick="BusiView()">
                <i class="icon-zoom-in bigger-110"></i>查看</button>
        </div>
        <table id="grid-Busi-table">
        </table>
    </div>
    <div class="ui-layout-center">
        <div class="btn-group">
            <button class="btn btn-sm btn-info">
                <i class="icon-refresh bigger-110"></i>刷新</button>
        </div>
        <table id="grid-User-table">
        </table>
    </div>
</div>
